﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using RoomSvc.Data;
using System.Data.SqlClient;
using System.IO;
using Newtonsoft.Json;
using System.Security.Cryptography;

namespace RoomSvc
{
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    
    public class RoomService
    {
        const int PAGE_LENGTH = 20;

        #region Connection Strings

        string sqlconnstring = "Data Source=23.23.80.142;Initial Catalog=DWSPROJECT;User Id=Administrator;Password=Grogan_01";

        void setFormatJson()
        {
            WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Json;
        }

        #endregion

        #region Web Get

		//Updated: 7/19/2012
        #region GET All Addresses
        
        [WebGet(UriTemplate = "address")]
        public Address[] GetAllAddress()
        {
            setFormatJson();
            Address[] address;
            int count = 0;

            using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
            {
                sqlServerConnection.Open();

                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT COUNT(*) FROM Address", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        while (sqlReader.Read())
                        {
                            count = (int)sqlReader[0];
                        }
                    }
                }

                address = new Address[count];

                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM Address", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        int i = 0;
                        while (sqlReader.Read())
                        {
                            address[i] = new Address();
                            address[i].Address_id = Convert.ToInt32(sqlReader["Address_id"]);
							address[i].Address_Type = new AddressType();
                            address[i].Address_Type.Address_Type_id = Convert.ToInt32(sqlReader["Address_Type_id"]);
                            address[i].street_address_1 = sqlReader["street_address_1"].ToString();
                            if (sqlReader["street_address_2"] != DBNull.Value)
                                address[i].street_address_2 = sqlReader["street_address_2"].ToString();
                            address[i].city = sqlReader["city"].ToString();
                            address[i].state = sqlReader["state"].ToString();
                            address[i].zip_code = sqlReader["zip_code"].ToString();
                            i++;
                        }

                    }
                }

				for (int i = 0; i < address.Length; i++)
				{
					using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM AddressType WHERE Address_Type_id = " + address[i].Address_Type.Address_Type_id , sqlServerConnection))
					{
						using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
						{
							while (sqlReader.Read())
							{
								 address[i].Address_Type.address_type_name = sqlReader["address_type_name"].ToString();
								 address[i].Address_Type.address_type_desc = sqlReader["address_type_desc"].ToString();
							}
						}
					}
				}
				
			}
			return address;
		}
   
        
        #endregion Get All Addresses
		//Updated: 7/19/2012
        #region Get Address using Id
		[WebGet(UriTemplate = "address/{addressid}")]
        public Address GetAddress(string addressId)
        {
            setFormatJson();
			Address address = new Address();

            using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
            {
                sqlServerConnection.Open();
                
                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM Address WHERE Address_id = " + addressId + ";", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        int i = 0;
                        while (sqlReader.Read())
                        {
                            address.Address_id = Convert.ToInt32(sqlReader["Address_id"]);
							address.Address_Type = new AddressType();
                            address.Address_Type.Address_Type_id = Convert.ToInt32(sqlReader["Address_Type_id"]);
                            address.street_address_1 = sqlReader["street_address_1"].ToString();
                            address.street_address_2 = sqlReader["street_address_2"].ToString();
                            address.city = sqlReader["city"].ToString();
                            address.state = sqlReader["state"].ToString();
                            address.zip_code = sqlReader["zip_code"].ToString();
                            i++;
                        }
                    }
                }

				using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM AddressType WHERE Address_Type_id = " + address.Address_Type.Address_Type_id , sqlServerConnection))
				{
					using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
					{
						while (sqlReader.Read())
						{
								address.Address_Type.address_type_name = sqlReader["address_type_name"].ToString();
								address.Address_Type.address_type_desc = sqlReader["address_type_desc"].ToString();
						}
					}
				}
            }

            return address;
		}
        #endregion Get Address using Id
		//Updated: 7/19/2012
        #region Get All Address Types
        
        [WebGet(UriTemplate = "address/type")]
        public AddressType[] GetAllAddressType()
        {
            setFormatJson();
            AddressType[] addressTypes;
            int count = 0;

            using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
            {
                sqlServerConnection.Open();

                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT COUNT(*) FROM AddressType", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        while (sqlReader.Read())
                        {
                            count = (int)sqlReader[0];
                        }
                    }
                }
                addressTypes = new AddressType[count];

                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM AddressType", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        int i = 0;
                        while (sqlReader.Read())
                        {
                            addressTypes[i] = new AddressType();
                            addressTypes[i].Address_Type_id = Convert.ToInt32(sqlReader["Address_Type_id"]);
                            addressTypes[i].address_type_name = sqlReader["address_type_name"].ToString();
                            addressTypes[i].address_type_desc = sqlReader["address_type_desc"].ToString();
                            i++;
                        }
                    }
                }
            }

            return addressTypes;
        }
        
        #endregion Get All Address Types
		//Updated: 7/19/2012
		#region Get Address Type using Id
		[WebGet(UriTemplate = "address/type/{addresstypeid}")]
        public AddressType GetAddressType(string addresstypeid)
        {
            setFormatJson();
			AddressType addressType = new AddressType();

            using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
            {
                sqlServerConnection.Open();
                
                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM AddressType WHERE Address_Type_id = " + addresstypeid + ";", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        int i = 0;
                        while (sqlReader.Read())
                        {
                            addressType.Address_Type_id = Convert.ToInt32(sqlReader["Address_Type_id"]);
                            addressType.address_type_name = sqlReader["address_type_name"].ToString();
                            addressType.address_type_desc = sqlReader["address_type_desc"].ToString();
                            i++;
                        }
                    }
                }
            }

            return addressType;
		}
		#endregion Get Address Type using Id
		//Updated: 7/19/2012
		#region Get All Persons
		[WebGet(UriTemplate = "person")]
        public Person[] GetAllPerson()
        {
            setFormatJson();
            Person[] persons;
			int count = -1;

            using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
            {
                sqlServerConnection.Open();

                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT COUNT(*) FROM Pers", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        while (sqlReader.Read())
                        {
                            count = (int)sqlReader[0];
                        }
                    }
                }
                persons = new Person[count];

                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM Pers", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        int i = 0;
                        while (sqlReader.Read())
                        {
                            persons[i] = new Person();
                            persons[i].Pers_id = Convert.ToInt32(sqlReader["Pers_id"]);
							persons[i].Pers_Type = new PersonType();
							persons[i].Pers_Type.Pers_Type_id = Convert.ToInt32(sqlReader["Pers_Type_id"]);
                            if (sqlReader["first_name"] != DBNull.Value)
                                persons[i].first_name = sqlReader["first_name"].ToString();
                            if (sqlReader["last_name"] != DBNull.Value)
							    persons[i].last_name = sqlReader["last_name"].ToString();
							persons[i].password = sqlReader["password"].ToString();
							persons[i].username = sqlReader["username"].ToString();
                            persons[i].date_birth = Convert.ToDateTime(sqlReader["date_birth"]);
                            persons[i].date_create = Convert.ToDateTime(sqlReader["date_create"].ToString());
                            if (sqlReader["date_modify"] != DBNull.Value)
                                persons[i].date_modify = Convert.ToDateTime(sqlReader["date_modify"].ToString());
							persons[i].phone = sqlReader["phone"].ToString();
							persons[i].email = sqlReader["email"].ToString();
							persons[i].email_confirm = sqlReader["email_confirm"].ToString();
                            persons[i].is_active = (Convert.ToInt16(sqlReader["is_active"]) != 0);
                            i++;
                        }
                    }
                }

				for (int i = 0; i < persons.Length; i++)
				{
					using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM PersType WHERE Pers_Type_id = " + persons[i].Pers_Type.Pers_Type_id , sqlServerConnection))
					{
						using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
						{
							while (sqlReader.Read())
							{
								 persons[i].Pers_Type.pers_type_name = sqlReader["pers_type_name"].ToString();
								 persons[i].Pers_Type.pers_type_desc = sqlReader["pers_type_desc"].ToString();
							}
						}
					}
				}

            }

			return persons;
        }
		#endregion Get All Persons
		//Updated: 7/19/2012
		#region Get Person using Id
		[WebGet(UriTemplate = "person/{personid}")]
        public Person GetPerson(string personid)
        {
            setFormatJson();
			Person person = new Person();

            using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
            {
                sqlServerConnection.Open();
                
                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM Pers WHERE Pers_id = " + personid + ";", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        int i = 0;
                        while (sqlReader.Read())
                        {
                            person = new Person();
                            person.Pers_id = Convert.ToInt32(sqlReader["Pers_id"]);
                            person.Pers_Type = new PersonType();
                            person.Pers_Type.Pers_Type_id = Convert.ToInt32(sqlReader["Pers_Type_id"]);
                            if (sqlReader["first_name"] != DBNull.Value)
                                person.first_name = sqlReader["first_name"].ToString();
                            if (sqlReader["last_name"] != DBNull.Value)
                                person.last_name = sqlReader["last_name"].ToString();
                            person.password = sqlReader["password"].ToString();
                            person.username = sqlReader["username"].ToString();
                            person.date_birth = Convert.ToDateTime(sqlReader["date_birth"]);
                            person.date_create = Convert.ToDateTime(sqlReader["date_create"].ToString());
                            if (sqlReader["date_modify"] != DBNull.Value)
                                person.date_modify = Convert.ToDateTime(sqlReader["date_modify"].ToString());
                            person.phone = sqlReader["phone"].ToString();
                            person.email = sqlReader["email"].ToString();
                            person.email_confirm = sqlReader["email_confirm"].ToString();
                            person.is_active = (Convert.ToInt16(sqlReader["is_active"]) != 0);
                            i++;
                        }
                    }
                }

				using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM PersType WHERE Pers_Type_id = " + person.Pers_Type.Pers_Type_id , sqlServerConnection))
				{
					using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
					{
						while (sqlReader.Read())
						{
								person.Pers_Type.pers_type_name = sqlReader["pers_type_name"].ToString();
								person.Pers_Type.pers_type_desc = sqlReader["pers_type_desc"].ToString();
						}
					}
				}
            }

            return person;
		}
		#endregion Get Peson using Id
		//Updated: 7/19/2012
		#region Get All Person Types
		[WebGet(UriTemplate = "person/type")]
        public PersonType[] GetAllPersonType()
        {
            setFormatJson();
			PersonType[] personTypes;
			int count = 0;

            using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
            {
                sqlServerConnection.Open();

                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT COUNT(*) FROM PersType", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        while (sqlReader.Read())
                        {
                            count = (int)sqlReader[0];
                        }
                    }
                }
                personTypes = new PersonType[count];


                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM PersType", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        int i = 0;
                        while (sqlReader.Read())
                        {
                            personTypes[i] = new PersonType();
                            personTypes[i].Pers_Type_id = Convert.ToInt32(sqlReader["Pers_Type_id"]);
                            personTypes[i].pers_type_name = sqlReader["pers_type_name"].ToString();
							personTypes[i].pers_type_desc = sqlReader["pers_type_desc"].ToString();
                            i++;
                        }
                    }
                }
            }

            return personTypes;
        }
		#endregion Get All Person Types
		//Updated: 7/19/2012
		#region Get Person Type using Id
		[WebGet(UriTemplate = "person/type/{persontypeid}")]
        public PersonType GetPersonType(string persontypeid)
        {
            setFormatJson();
			PersonType personType = new PersonType();

            using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
            {
                sqlServerConnection.Open();
                
                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM PersType WHERE Pers_Type_id = " + persontypeid + ";", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        int i = 0;
                        while (sqlReader.Read())
                        {
                            personType.Pers_Type_id = Convert.ToInt32(sqlReader["Pers_Type_id"]);
                            personType.pers_type_name = sqlReader["pers_type_name"].ToString();
							personType.pers_type_desc = sqlReader["pers_type_desc"].ToString();
                            i++;
                        }
                    }
                }
            }

            return personType;
		}
		#endregion Get Person Type using Id
		//Updated: 7/19/2012
		#region Get All Listings
		[WebGet(UriTemplate = "listing")]
        public Listing[] GetAllListing()
        {
            setFormatJson();
			Listing[] listings;
			int count = 0;
			
            using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
            {
                sqlServerConnection.Open();

                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT COUNT(*) FROM Listing", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        while (sqlReader.Read())
                        {
                            count = (int)sqlReader[0];
                        }
                    }
                }

                listings = new Listing[count];

                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM Listing", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        int i = 0;
                        while (sqlReader.Read())
                        {
                            listings[i] = new Listing();
                            listings[i].Listing_id = Convert.ToInt32(sqlReader["Listing_id"]);
							listings[i].Listing_Type = new ListingType();
							listings[i].Listing_Type.Listing_Type_id = Convert.ToInt32(sqlReader["Listing_Type_id"]);
							listings[i].Pers = new Person();
							listings[i].Pers.Pers_id = Convert.ToInt32(sqlReader["Pers_id"]);
							listings[i].Address = new Address();
							listings[i].Address.Address_id = Convert.ToInt32(sqlReader["Address_id"]);
							listings[i].Utility = new Utility();
                            if(sqlReader["Utility_id"] != DBNull.Value)
                                listings[i].Utility.Utility_id = Convert.ToInt32(sqlReader["Utility_id"]);
                            listings[i].listing_title = sqlReader["listing_title"].ToString();
							listings[i].listing_desc = sqlReader["listing_desc"].ToString();
							listings[i].listing_rate = Convert.ToInt32(sqlReader["listing_rate"]);
							listings[i].roommates = Convert.ToInt32(sqlReader["roommates"]);
                            if (sqlReader["smoking"] != DBNull.Value)
							    listings[i].smoking = Convert.ToInt32(sqlReader["smoking"]);
                            if (sqlReader["gender"] != DBNull.Value)
							    listings[i].gender = Convert.ToString(sqlReader["gender"]);
                            if (sqlReader["furnished"] != DBNull.Value)
							    listings[i].furnished = Convert.ToInt32(sqlReader["furnished"]);
                            if (sqlReader["square_ft"] != DBNull.Value)
							    listings[i].square_ft = Convert.ToInt32(sqlReader["square_ft"]);
                            listings[i].date_term_start = Convert.ToDateTime(sqlReader["date_term_start"]);
                            listings[i].date_term_end = Convert.ToDateTime(sqlReader["date_term_end"]);
                            listings[i].date_listing_expire = Convert.ToDateTime(sqlReader["date_listing_expire"]);
                            listings[i].is_active = (Convert.ToInt16(sqlReader["is_active"]) != 0);
                            i++;
                        }
                    }
                }

				string Address_id = "0";
				string Person_id = "0";
				string Utility_id = "0";
				Address address;
				Person person;
				Utility utility;
				for (int i = 0; i < listings.Length; i++)
				{
					Address_id = Convert.ToString(listings[i].Address.Address_id);
					Person_id = Convert.ToString(listings[i].Pers.Pers_id);
					Utility_id = Convert.ToString(listings[i].Utility.Utility_id);
					address = listings[i].Address;
					person = listings[i].Pers;
					utility = listings[i].Utility;

					using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM ListingType WHERE Listing_Type_id = " + listings[i].Listing_Type.Listing_Type_id , sqlServerConnection))
					{
						using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
						{
							while (sqlReader.Read())
							{
								 listings[i].Listing_Type.listing_type_name = sqlReader["listing_type_name"].ToString();
								 listings[i].Listing_Type.listing_type_desc = sqlReader["listing_type_desc"].ToString();
							}
						}
					}

					using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM Address WHERE Address_id = " + Address_id + ";", sqlServerConnection))
					{
						using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
						{
							while (sqlReader.Read())
							{
								address.Address_id = Convert.ToInt32(sqlReader["Address_id"]);
								address.Address_Type = new AddressType();
								address.Address_Type.Address_Type_id = Convert.ToInt32(sqlReader["Address_Type_id"]);
								address.street_address_1 = sqlReader["street_address_1"].ToString();
								address.street_address_2 = sqlReader["street_address_2"].ToString();
								address.city = sqlReader["city"].ToString();
								address.state = sqlReader["state"].ToString();
								address.zip_code = sqlReader["zip_code"].ToString();
							}
						}
					}

					using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM AddressType WHERE Address_Type_id = " + address.Address_Type.Address_Type_id , sqlServerConnection))
					{
						using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
						{
							while (sqlReader.Read())
							{
									address.Address_Type.address_type_name = sqlReader["address_type_name"].ToString();
									address.Address_Type.address_type_desc = sqlReader["address_type_desc"].ToString();
							}
						}
					}

					using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM Pers WHERE Pers_id = " + Person_id + ";", sqlServerConnection))
					{
						using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
						{
							while (sqlReader.Read())
							{
								person = new Person();
								person.Pers_id = Convert.ToInt32(sqlReader["Pers_id"]);
								person.Pers_Type = new PersonType();
								person.Pers_Type.Pers_Type_id = Convert.ToInt32(sqlReader["Pers_Type_id"]);
								if (sqlReader["first_name"] != DBNull.Value)
									person.first_name = sqlReader["first_name"].ToString();
								if (sqlReader["last_name"] != DBNull.Value)
									person.last_name = sqlReader["last_name"].ToString();
								person.password = sqlReader["password"].ToString();
								person.username = sqlReader["username"].ToString();
								person.date_birth = Convert.ToDateTime(sqlReader["date_birth"]);
								person.date_create = Convert.ToDateTime(sqlReader["date_create"].ToString());
								if (sqlReader["date_modify"] != DBNull.Value)
									person.date_modify = Convert.ToDateTime(sqlReader["date_modify"].ToString());
								person.phone = sqlReader["phone"].ToString();
								person.email = sqlReader["email"].ToString();
								person.email_confirm = sqlReader["email_confirm"].ToString();
								person.is_active = (Convert.ToInt16(sqlReader["is_active"]) != 0);
							}
						}
					}

					using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM PersType WHERE Pers_Type_id = " + person.Pers_Type.Pers_Type_id , sqlServerConnection))
					{
						using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
						{
							while (sqlReader.Read())
							{
									person.Pers_Type.pers_type_name = sqlReader["pers_type_name"].ToString();
									person.Pers_Type.pers_type_desc = sqlReader["pers_type_desc"].ToString();
							}
						}
					}

					using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM Utilities WHERE Utility_id = " + Utility_id + ";", sqlServerConnection))
					{
						using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
						{
							while (sqlReader.Read())
							{
								utility = new Utility();
								utility.Utility_id = Convert.ToInt32(sqlReader["Utility_id"]);
								if (sqlReader["water"] != DBNull.Value)
									utility.water = sqlReader["water"].ToString();
								if (sqlReader["power"] != DBNull.Value)
									utility.power = sqlReader["power"].ToString();
								if (sqlReader["cable"] != DBNull.Value)
									utility.cable = sqlReader["cable"].ToString();
								if (sqlReader["internet"] != DBNull.Value)
									utility.internet = sqlReader["internet"].ToString();
								if (sqlReader["other"] != DBNull.Value)
									utility.other = sqlReader["other"].ToString();
							}
						}
					}

				}

            }
			/*
			string Address_id = "0";
			string Person_id = "0";
			string Utility_id = "0";
			for (int i = 0; i < listings.Length; i++)
			{	
				Address_id = Convert.ToString(listings[i].Address.Address_id);
				Person_id = Convert.ToString(listings[i].Pers.Pers_id);
				Utility_id = Convert.ToString(listings[i].Utility.Utility_id);
				listings[i].Address = GetAddress(Address_id);
				listings[i].Pers = GetPerson(Person_id);
				listings[i].Utility = GetUtility(Utility_id);
			}
			*/

            return listings;
        }
		#endregion Get All Listings
		//Updated: 7/19/2012
		#region Get Listing using Id
		[WebGet(UriTemplate = "listing/{listingid}")]
        public Listing GetListing(string listingid)
        {
            setFormatJson();
			Listing listing = new Listing();

            using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
            {
                sqlServerConnection.Open();
                
                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM Listing WHERE Listing_id = " + listingid + ";", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        int i = 0;
                        while (sqlReader.Read())
                        {
                            listing = new Listing();
                            listing.Listing_id = Convert.ToInt32(sqlReader["Listing_id"]);
                            listing.Listing_Type = new ListingType();
                            listing.Listing_Type.Listing_Type_id = Convert.ToInt32(sqlReader["Listing_Type_id"]);
                            listing.Pers = new Person();
                            listing.Pers.Pers_id = Convert.ToInt32(sqlReader["Pers_id"]);
                            listing.Address = new Address();
                            listing.Address.Address_id = Convert.ToInt32(sqlReader["Address_id"]);
                            listing.Utility = new Utility();
                            if (sqlReader["Utility_id"] != DBNull.Value)
                                listing.Utility.Utility_id = Convert.ToInt32(sqlReader["Utility_id"]);
                            listing.listing_title = sqlReader["listing_title"].ToString();
                            listing.listing_desc = sqlReader["listing_desc"].ToString();
                            listing.listing_rate = Convert.ToInt32(sqlReader["listing_rate"]);
                            listing.roommates = Convert.ToInt32(sqlReader["roommates"]);
                            if (sqlReader["smoking"] != DBNull.Value)
                                listing.smoking = Convert.ToInt32(sqlReader["smoking"]);
                            if (sqlReader["gender"] != DBNull.Value)
                                listing.gender = Convert.ToString(sqlReader["gender"]);
                            if (sqlReader["furnished"] != DBNull.Value)
                                listing.furnished = Convert.ToInt32(sqlReader["furnished"]);
                            if (sqlReader["square_ft"] != DBNull.Value)
                                listing.square_ft = Convert.ToInt32(sqlReader["square_ft"]);
                            listing.is_active = (Convert.ToInt16(sqlReader["is_active"]) != 0);
                            i++;
                        }
                    }
                }



				using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM ListingType WHERE Listing_Type_id = " + listing.Listing_Type.Listing_Type_id , sqlServerConnection))
				{
					using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
					{
						while (sqlReader.Read())
						{
								listing.Listing_Type.listing_type_name = sqlReader["listing_type_name"].ToString();
								listing.Listing_Type.listing_type_desc = sqlReader["listing_type_desc"].ToString();
						}
					}
				}

            }

			string Address_id = Convert.ToString(listing.Address.Address_id);
			string Person_id = Convert.ToString(listing.Pers.Pers_id);
			string Utility_id = Convert.ToString(listing.Utility.Utility_id);
			listing.Address = GetAddress(Address_id);
			listing.Pers = GetPerson(Person_id);
			listing.Utility = GetUtility(Utility_id);

            return listing;			
        }

            
		
		#endregion Get Listing using Id
        //Updated: 7/24/2012
        #region GetListingPage
        [WebGet(UriTemplate = "listing/page/{pagenum}")]
        public Listing[] GetListingPage(string pagenum)
        {
            setFormatJson();
            Listing[] allListings;
            int count = 0;
            int pageNum = Convert.ToInt32(pagenum);

            if(pageNum < 1)
                return new Listing[0];

            Listing[] listings = null;

            using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
            {
                sqlServerConnection.Open();

                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT COUNT(*) FROM Listing", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        while (sqlReader.Read())
                        {
                            count = (int)sqlReader[0];
                        }
                    }
                }

                allListings = new Listing[count];

                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM Listing", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        int i = 0;
                        while (sqlReader.Read())
                        {
                            allListings[i] = new Listing();
                            allListings[i].Listing_id = Convert.ToInt32(sqlReader["Listing_id"]);
                            allListings[i].Listing_Type = new ListingType();
                            allListings[i].Listing_Type.Listing_Type_id = Convert.ToInt32(sqlReader["Listing_Type_id"]);
                            allListings[i].Pers = new Person();
                            allListings[i].Pers.Pers_id = Convert.ToInt32(sqlReader["Pers_id"]);
                            allListings[i].Address = new Address();
                            allListings[i].Address.Address_id = Convert.ToInt32(sqlReader["Address_id"]);
                            allListings[i].Utility = new Utility();
                            if (sqlReader["Utility_id"] != DBNull.Value)
                                allListings[i].Utility.Utility_id = Convert.ToInt32(sqlReader["Utility_id"]);
                            allListings[i].listing_title = sqlReader["listing_title"].ToString();
                            allListings[i].listing_desc = sqlReader["listing_desc"].ToString();
                            allListings[i].listing_rate = Convert.ToInt32(sqlReader["listing_rate"]);
                            allListings[i].roommates = Convert.ToInt32(sqlReader["roommates"]);
                            if (sqlReader["smoking"] != DBNull.Value)
                                allListings[i].smoking = Convert.ToInt32(sqlReader["smoking"]);
                            if (sqlReader["gender"] != DBNull.Value)
                                allListings[i].gender = Convert.ToString(sqlReader["gender"]);
                            if (sqlReader["furnished"] != DBNull.Value)
                                allListings[i].furnished = Convert.ToInt32(sqlReader["furnished"]);
                            if (sqlReader["square_ft"] != DBNull.Value)
                                allListings[i].square_ft = Convert.ToInt32(sqlReader["square_ft"]);
                            allListings[i].date_term_start = Convert.ToDateTime(sqlReader["date_term_start"]);
                            allListings[i].date_term_end = Convert.ToDateTime(sqlReader["date_term_end"]);
                            allListings[i].date_listing_expire = Convert.ToDateTime(sqlReader["date_listing_expire"]);
                            allListings[i].is_active = (Convert.ToInt16(sqlReader["is_active"]) != 0);
                            i++;
                        }
                    }
                }

                //Page seperation
                List<Listing> listingPage = new List<Listing>();
                for (int i = (pageNum - 1) * PAGE_LENGTH; i < ((pageNum - 1) * PAGE_LENGTH) + PAGE_LENGTH && i < allListings.Length; i++)
                {
                    listingPage.Add(allListings[i]);
                }
                listings = listingPage.ToArray();

                string Address_id = "0";
                string Person_id = "0";
                string Utility_id = "0";
                Address address;
                Person person;
                Utility utility;
                for (int i = 0; i < listings.Length; i++)
                {
                    Address_id = Convert.ToString(listings[i].Address.Address_id);
                    Person_id = Convert.ToString(listings[i].Pers.Pers_id);
                    Utility_id = Convert.ToString(listings[i].Utility.Utility_id);
                    address = listings[i].Address;
                    person = listings[i].Pers;
                    utility = listings[i].Utility;

                    using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM ListingType WHERE Listing_Type_id = " + listings[i].Listing_Type.Listing_Type_id, sqlServerConnection))
                    {
                        using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                        {
                            while (sqlReader.Read())
                            {
                                listings[i].Listing_Type.listing_type_name = sqlReader["listing_type_name"].ToString();
                                listings[i].Listing_Type.listing_type_desc = sqlReader["listing_type_desc"].ToString();
                            }
                        }
                    }

                    using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM Address WHERE Address_id = " + Address_id + ";", sqlServerConnection))
                    {
                        using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                        {
                            while (sqlReader.Read())
                            {
                                address.Address_id = Convert.ToInt32(sqlReader["Address_id"]);
                                address.Address_Type = new AddressType();
                                address.Address_Type.Address_Type_id = Convert.ToInt32(sqlReader["Address_Type_id"]);
                                address.street_address_1 = sqlReader["street_address_1"].ToString();
                                address.street_address_2 = sqlReader["street_address_2"].ToString();
                                address.city = sqlReader["city"].ToString();
                                address.state = sqlReader["state"].ToString();
                                address.zip_code = sqlReader["zip_code"].ToString();
                            }
                        }
                    }

                    using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM AddressType WHERE Address_Type_id = " + address.Address_Type.Address_Type_id, sqlServerConnection))
                    {
                        using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                        {
                            while (sqlReader.Read())
                            {
                                address.Address_Type.address_type_name = sqlReader["address_type_name"].ToString();
                                address.Address_Type.address_type_desc = sqlReader["address_type_desc"].ToString();
                            }
                        }
                    }

                    using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM Pers WHERE Pers_id = " + Person_id + ";", sqlServerConnection))
                    {
                        using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                        {
                            while (sqlReader.Read())
                            {
                                person = new Person();
                                person.Pers_id = Convert.ToInt32(sqlReader["Pers_id"]);
                                person.Pers_Type = new PersonType();
                                person.Pers_Type.Pers_Type_id = Convert.ToInt32(sqlReader["Pers_Type_id"]);
                                if (sqlReader["first_name"] != DBNull.Value)
                                    person.first_name = sqlReader["first_name"].ToString();
                                if (sqlReader["last_name"] != DBNull.Value)
                                    person.last_name = sqlReader["last_name"].ToString();
                                person.password = sqlReader["password"].ToString();
                                person.username = sqlReader["username"].ToString();
                                person.date_birth = Convert.ToDateTime(sqlReader["date_birth"]);
                                person.date_create = Convert.ToDateTime(sqlReader["date_create"].ToString());
                                if (sqlReader["date_modify"] != DBNull.Value)
                                    person.date_modify = Convert.ToDateTime(sqlReader["date_modify"].ToString());
                                person.phone = sqlReader["phone"].ToString();
                                person.email = sqlReader["email"].ToString();
                                person.email_confirm = sqlReader["email_confirm"].ToString();
                                person.is_active = (Convert.ToInt16(sqlReader["is_active"]) != 0);
                            }
                        }
                    }

                    using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM PersType WHERE Pers_Type_id = " + person.Pers_Type.Pers_Type_id, sqlServerConnection))
                    {
                        using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                        {
                            while (sqlReader.Read())
                            {
                                person.Pers_Type.pers_type_name = sqlReader["pers_type_name"].ToString();
                                person.Pers_Type.pers_type_desc = sqlReader["pers_type_desc"].ToString();
                            }
                        }
                    }

                    using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM Utilities WHERE Utility_id = " + Utility_id + ";", sqlServerConnection))
                    {
                        using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                        {
                            while (sqlReader.Read())
                            {
                                utility = new Utility();
                                utility.Utility_id = Convert.ToInt32(sqlReader["Utility_id"]);
                                if (sqlReader["water"] != DBNull.Value)
                                    utility.water = sqlReader["water"].ToString();
                                if (sqlReader["power"] != DBNull.Value)
                                    utility.power = sqlReader["power"].ToString();
                                if (sqlReader["cable"] != DBNull.Value)
                                    utility.cable = sqlReader["cable"].ToString();
                                if (sqlReader["internet"] != DBNull.Value)
                                    utility.internet = sqlReader["internet"].ToString();
                                if (sqlReader["other"] != DBNull.Value)
                                    utility.other = sqlReader["other"].ToString();
                            }
                        }
                    }

                }

            }
            /*
            string Address_id = "0";
            string Person_id = "0";
            string Utility_id = "0";
            for (int i = 0; i < listings.Length; i++)
            {	
                Address_id = Convert.ToString(listings[i].Address.Address_id);
                Person_id = Convert.ToString(listings[i].Pers.Pers_id);
                Utility_id = Convert.ToString(listings[i].Utility.Utility_id);
                listings[i].Address = GetAddress(Address_id);
                listings[i].Pers = GetPerson(Person_id);
                listings[i].Utility = GetUtility(Utility_id);
            }
            */

            return listings;
        }
        #endregion
        //Updated: 7/20/2012
        #region Get All Listing Types
        [WebGet(UriTemplate = "listing/type")]
        public ListingType[] GetAllListingType()
        {
            setFormatJson();
            ListingType[] listingTypes;
            int count = 0;

            using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
            {
                sqlServerConnection.Open();
                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT COUNT(*) FROM ListingType", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        while (sqlReader.Read())
                        {
                            count = (int)sqlReader[0];
                        }
                    }
                }
                listingTypes = new ListingType[count];


                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM ListingType", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        int i = 0;
                        while (sqlReader.Read())
                        {
                            listingTypes[i] = new ListingType();
                            listingTypes[i].Listing_Type_id = Convert.ToInt32(sqlReader["Listing_Type_id"]);
                            listingTypes[i].listing_type_name = sqlReader["listing_type_name"].ToString();
                            listingTypes[i].listing_type_desc = sqlReader["listing_type_desc"].ToString();
                            i++;
                        }
                    }
                }
            }

            return listingTypes;
        }
        #endregion Get All Listing Types
        //Updated: 7/20/2012
        #region Get Listing Type using Id
        [WebGet(UriTemplate = "listing/type/{typeid}")]
        public ListingType ListingType(string typeid)
        {
            setFormatJson();
            ListingType listingType = new ListingType();

            using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
            {
                sqlServerConnection.Open();

                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM ListingType WHERE Listing_Type_id = " + typeid + ";", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        while (sqlReader.Read())
                        {
                            listingType = new ListingType();
                            listingType.Listing_Type_id = Convert.ToInt32(sqlReader["Listing_Type_id"]);
                            listingType.listing_type_name = sqlReader["listing_type_name"].ToString();
                            listingType.listing_type_desc = sqlReader["listing_type_desc"].ToString();
                        }
                    }
                }
            }

            return listingType;
        }
        #endregion Get Listing Type using Id
        //Updated: 7/19/2012
		#region Get All Utility
		[WebGet(UriTemplate = "utility")]
        public Utility[] GetAllUtility()
        {
            setFormatJson();
			Utility[] utilities;
			int count = 0;
			

            using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
            {
                sqlServerConnection.Open();
                //Get the number of permissions to expect from the database
                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT COUNT(*) FROM Utilities", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        while (sqlReader.Read())
                        {
                            count = (int)sqlReader[0];
                        }
                    }
                }
                utilities = new Utility[count];

                //populate the Permission array
                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM Utilities", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        int i = 0;
                        while (sqlReader.Read())
                        {
                            utilities[i] = new Utility();
                            utilities[i].Utility_id = Convert.ToInt32(sqlReader["Utility_id"]);
                            if (sqlReader["water"] != DBNull.Value)
                                utilities[i].water = sqlReader["water"].ToString();
                            if (sqlReader["power"] != DBNull.Value)
							    utilities[i].power = sqlReader["power"].ToString();
                            if (sqlReader["cable"] != DBNull.Value)
							    utilities[i].cable = sqlReader["cable"].ToString();
                            if (sqlReader["internet"] != DBNull.Value)
							    utilities[i].internet = sqlReader["internet"].ToString();
                            if (sqlReader["other"] != DBNull.Value)
							    utilities[i].other = sqlReader["other"].ToString();
                            i++;
                        }
                    }
                }
            }

            return utilities;
        }
		#endregion Get Utility using Id
		//Updated: 7/19/2012
		#region Get Utility using Id
		[WebGet(UriTemplate = "utility/{utilityid}")]
        public Utility GetUtility(string utilityid)
        {
            setFormatJson();
			Utility utility = new Utility();

            using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
            {
                sqlServerConnection.Open();
                
                using (SqlCommand sqlServerCommand = new SqlCommand("SELECT * FROM Utilities WHERE Utility_id = " + utilityid + ";", sqlServerConnection))
                {
                    using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                    {
                        int i = 0;
                        while (sqlReader.Read())
                        {
                            utility = new Utility();
                            utility.Utility_id = Convert.ToInt32(sqlReader["Utility_id"]);
                            if (sqlReader["water"] != DBNull.Value)
                                utility.water = sqlReader["water"].ToString();
                            if (sqlReader["power"] != DBNull.Value)
                                utility.power = sqlReader["power"].ToString();
                            if (sqlReader["cable"] != DBNull.Value)
                                utility.cable = sqlReader["cable"].ToString();
                            if (sqlReader["internet"] != DBNull.Value)
                                utility.internet = sqlReader["internet"].ToString();
                            if (sqlReader["other"] != DBNull.Value)
                                utility.other = sqlReader["other"].ToString();
                            i++;
                        }
                    }
                }
            }

            return utility;
		}
		#endregion Get Utility using Id

        #endregion Web Get

        #region Web Invoke

        //Updated: 7/19/2012
        #region New Address
        [WebInvoke(Method = "POST", UriTemplate = "address/new", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        PostResponse NewAddress(Stream streamdata)
        {
            setFormatJson();
            PostResponse response = new PostResponse();
            response.ResponseCode = PostResponseCode.POST_OK;

            StreamReader reader = new StreamReader(streamdata);
            string res = String.Empty;
            try
            {
                res = reader.ReadToEnd();
            }
            catch (IOException e)
            {
                response.ResponseCode = PostResponseCode.POST_IO_ERROR;
                return response;
            }
            reader.Close();
            reader.Dispose();

            Address a = null;
            try
            {
                a = (Address)JsonConvert.DeserializeObject(res, typeof(Address));
            }
            catch (JsonSerializationException e)
            {
                response.ResponseCode = PostResponseCode.POST_DESERIALIZATION_ERROR;
                return response;
            }
            catch (JsonReaderException e)
            {
                response.ResponseCode = PostResponseCode.POST_JSON_READER_ERROR;
                return response;
            }
            
            try
            {
                using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
                {
                    sqlServerConnection.Open();
                    SqlCommand sqlServerCommand;

                    using (sqlServerCommand = new SqlCommand("INSERT INTO Address (Address_Type_id, street_address_1, street_address_2, city, state, zip_code) VALUES (" 
                        + a.Address_Type.Address_Type_id + ",'" + a.street_address_1 + "','" + a.street_address_2 + "','" + a.city + "','" + a.state + "','" + a.zip_code + "');", sqlServerConnection))

                    {
                        sqlServerCommand.ExecuteNonQuery();
                    }
                }
            }
            catch (SqlException e)
            {
                response.ResponseCode = PostResponseCode.POST_SQL_ERROR;
                return response;
            }
            catch(NullReferenceException e)
            {
                response.ResponseCode = PostResponseCode.POST_NULL_MEMBER_ERROR;
                return response;
            }

            return response;
        }
		#endregion INSERT new Address
        //Updated: 7/19/2012
        #region Update Address
        [WebInvoke(Method = "POST", UriTemplate = "address/update", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        PostResponse UpdateAddress(Stream streamdata)
        {
            setFormatJson();
            PostResponse response = new PostResponse();
            response.ResponseCode = PostResponseCode.POST_OK;

            StreamReader reader = new StreamReader(streamdata);
            string res = String.Empty;
            try
            {
                res = reader.ReadToEnd();
            }
            catch (IOException e)
            {
                response.ResponseCode = PostResponseCode.POST_IO_ERROR;
                return response;
            }
            reader.Close();
            reader.Dispose();

            Address a = null;
            try
            {
                a = (Address)JsonConvert.DeserializeObject(res, typeof(Address));
            }
            catch (JsonSerializationException e)
            {
                response.ResponseCode = PostResponseCode.POST_DESERIALIZATION_ERROR;
                return response;
            }
            catch (JsonReaderException e)
            {
                response.ResponseCode = PostResponseCode.POST_JSON_READER_ERROR;
                return response;
            }

            try
            {
                using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
                {
                    sqlServerConnection.Open();
                    SqlCommand sqlServerCommand;

                    using (sqlServerCommand = new SqlCommand("UPDATE Address SET Address_Type_id = " + a.Address_Type.Address_Type_id + 
                                                                               ",street_address_1 = " + a.street_address_1 +
                                                                               ",street_address_2 = " + a.street_address_2 + 
                                                                               ",city = " + a.city +
                                                                               ",state = " + a.state + 
                                                                               ",zip_code = " + a.zip_code + 
                                                                               " WHERE Address_id = " + a.Address_id + ";", sqlServerConnection))
                    {
                        sqlServerCommand.ExecuteNonQuery();
                    }
                }
            }
            catch (SqlException e)
            {
                response.ResponseCode = PostResponseCode.POST_SQL_ERROR;
                return response;
            }
            catch (NullReferenceException e)
            {
                response.ResponseCode = PostResponseCode.POST_NULL_MEMBER_ERROR;
                return response;
            }

            return response;
        }
        #endregion Update Address
        //Updated: 7/19/2012
        #region Delete Address
        [WebInvoke(Method = "POST", UriTemplate = "address/delete", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        PostResponse DeleteAddress(Stream streamdata)
        {
            setFormatJson();
            PostResponse response = new PostResponse();
            response.ResponseCode = PostResponseCode.POST_OK;

            StreamReader reader = new StreamReader(streamdata);
            string res = String.Empty;
            try
            {
                res = reader.ReadToEnd();
            }
            catch (IOException e)
            {
                response.ResponseCode = PostResponseCode.POST_IO_ERROR;
                return response;
            }
            reader.Close();
            reader.Dispose();

            Address a = null;

            try
            {
                a = (Address)JsonConvert.DeserializeObject(res, typeof(Address));
            }
            catch (JsonSerializationException e)
            {
                response.ResponseCode = PostResponseCode.POST_DESERIALIZATION_ERROR;
                return response;
            }
            catch (JsonReaderException e)
            {
                response.ResponseCode = PostResponseCode.POST_JSON_READER_ERROR;
                return response;
            }

            try
            {
                using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
                {
                    sqlServerConnection.Open();
                    SqlCommand sqlServerCommand;

                    using (sqlServerCommand = new SqlCommand("UPDATE Address SET is_active = 0 WHERE Address_id = " + a.Address_id, sqlServerConnection))
                    {
                        sqlServerCommand.ExecuteNonQuery();
                    }
                }
            }
            catch (SqlException e)
            {
                response.ResponseCode = PostResponseCode.POST_SQL_ERROR;
                return response;
            }
            catch (NullReferenceException e)
            {
                response.ResponseCode = PostResponseCode.POST_NULL_MEMBER_ERROR;
                return response;
            }

            return response;
        }
        #endregion Delete Address
        //Updated: 7/19/2012
        #region New Person
        [WebInvoke(Method = "POST", UriTemplate = "person/new", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        PostResponse NewPerson(Stream streamdata)
        {
            setFormatJson();
            PostResponse response = new PostResponse();
            response.ResponseCode = PostResponseCode.POST_OK;

            StreamReader reader = new StreamReader(streamdata);
            string res = String.Empty;
            try
            {
                res = reader.ReadToEnd();
            }
            catch (IOException e)
            {
                response.ResponseCode = PostResponseCode.POST_IO_ERROR;
                return response;
            }
            reader.Close();
            reader.Dispose();

            Person p = null;
            try
            {
                p = (Person)JsonConvert.DeserializeObject(res, typeof(Person));
            }
            catch (JsonSerializationException e)
            {
                response.ResponseCode = PostResponseCode.POST_DESERIALIZATION_ERROR;
                return response;
            }
            catch (JsonReaderException e)
            {
                response.ResponseCode = PostResponseCode.POST_JSON_READER_ERROR;
                return response;
            }

            try
            {
                using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
                {
                    sqlServerConnection.Open();
                    SqlCommand sqlServerCommand;

                    byte[] tmpSource = ASCIIEncoding.ASCII.GetBytes(p.username);
                    byte[] tmpHash = new MD5CryptoServiceProvider().ComputeHash(tmpSource);

                    p.email_confirm = ByteArrayToString(tmpHash);

                    using (sqlServerCommand = new SqlCommand("INSERT INTO Pers (Pers_Type_id, first_name, last_name, password, username, phone, email, email_confirm, is_active) VALUES ("
                        + p.Pers_Type.Pers_Type_id + ",'" + p.first_name + "','" + p.last_name + "','" + p.password + "','" + p.username + "','" + p.phone + "','" + p.email + "','" + p.email_confirm + "',1);", sqlServerConnection))
                    {
                        sqlServerCommand.ExecuteNonQuery();
                    }
                }
            }
            catch (SqlException e)
            {
                response.ResponseCode = PostResponseCode.POST_SQL_ERROR;
                return response;
            }
            catch (NullReferenceException e)
            {
                response.ResponseCode = PostResponseCode.POST_NULL_MEMBER_ERROR;
                return response;
            }

            return response;
        }

        static string ByteArrayToString(byte[] arrInput)
        {
            int i;
            StringBuilder sOutput = new StringBuilder(arrInput.Length);
            for (i = 0; i < arrInput.Length; i++)
            {
                sOutput.Append(arrInput[i].ToString("X2"));
            }
            return sOutput.ToString();
        }

        #endregion New Person
        //Updated: 7/23/2012
        #region Update Person
        [WebInvoke(Method = "POST", UriTemplate = "person/update", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        PostResponse UpdatePerson(Stream streamdata)
        {
            setFormatJson();
            PostResponse response = new PostResponse();
            response.ResponseCode = PostResponseCode.POST_OK;

            StreamReader reader = new StreamReader(streamdata);
            string res = String.Empty;
            try
            {
                res = reader.ReadToEnd();
            }
            catch (IOException e)
            {
                response.ResponseCode = PostResponseCode.POST_IO_ERROR;
                return response;
            }
            reader.Close();
            reader.Dispose();

            Person p = null;
            try
            {
                p = (Person)JsonConvert.DeserializeObject(res, typeof(Person));
            }
            catch (JsonSerializationException e)
            {
                response.ResponseCode = PostResponseCode.POST_DESERIALIZATION_ERROR;
                return response;
            }
            catch (JsonReaderException e)
            {
                response.ResponseCode = PostResponseCode.POST_JSON_READER_ERROR;
                return response;
            }

            try
            {
                using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
                {
                    sqlServerConnection.Open();
                    SqlCommand sqlServerCommand;

                    using (sqlServerCommand = new SqlCommand("UPDATE Pers SET Person_Type_id = " + p.Pers_Type.Pers_Type_id +
                                                                               ",first_name = " + p.first_name +
                                                                               ",last_name = " + p.last_name +
                                                                               ",password = " + p.password +
                                                                               ",username = " + p.username +
                                                                               ",phone = " + p.phone +
                                                                               ",email = " + p.email +
                                                                               ",email_confirm = " + p.email_confirm +
                                                                               ",is_active = " + p.is_active + " WHERE Pers_id = " + p.Pers_id + ";", sqlServerConnection))
                    {
                        sqlServerCommand.ExecuteNonQuery();
                    }
                }
            }
            catch (SqlException e)
            {
                response.ResponseCode = PostResponseCode.POST_SQL_ERROR;
                return response;
            }
            catch (NullReferenceException e)
            {
                response.ResponseCode = PostResponseCode.POST_NULL_MEMBER_ERROR;
                return response;
            }

            return response;
        }
        #endregion Update Person
        //Updated: 7/19/2012
        #region Delete Person
        [WebInvoke(Method = "POST", UriTemplate = "person/delete", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        PostResponse DeletePerson(Stream streamdata)
        {
            setFormatJson();
            PostResponse response = new PostResponse();
            response.ResponseCode = PostResponseCode.POST_OK;

            StreamReader reader = new StreamReader(streamdata);
            string res = String.Empty;
            try
            {
                res = reader.ReadToEnd();
            }
            catch (IOException e)
            {
                response.ResponseCode = PostResponseCode.POST_IO_ERROR;
                return response;
            }
            reader.Close();
            reader.Dispose();

            Person p = null;

            try
            {
                p = (Person)JsonConvert.DeserializeObject(res, typeof(Person));
            }
            catch (JsonSerializationException e)
            {
                response.ResponseCode = PostResponseCode.POST_DESERIALIZATION_ERROR;
                return response;
            }
            catch (JsonReaderException e)
            {
                response.ResponseCode = PostResponseCode.POST_JSON_READER_ERROR;
                return response;
            }

            try
            {
                using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
                {
                    sqlServerConnection.Open();
                    SqlCommand sqlServerCommand;

                    using (sqlServerCommand = new SqlCommand("UPDATE Pers SET is_active = 0 WHERE Pers_id = " + p.Pers_id, sqlServerConnection))
                    {
                        sqlServerCommand.ExecuteNonQuery();
                    }
                }
            }
            catch (SqlException e)
            {
                response.ResponseCode = PostResponseCode.POST_SQL_ERROR;
                return response;
            }
            catch (NullReferenceException e)
            {
                response.ResponseCode = PostResponseCode.POST_NULL_MEMBER_ERROR;
                return response;
            }

            return response;
        }
        #endregion Delete Person
        //Updated: 7/19/2012
        #region New Listing
        [WebInvoke(Method = "POST", UriTemplate = "listing/new", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        PostResponse NewListing(Stream streamdata)
        {
            setFormatJson();
            PostResponse response = new PostResponse();
            response.ResponseCode = PostResponseCode.POST_OK;

            StreamReader reader = new StreamReader(streamdata);
            string res = String.Empty;
            try
            {
                res = reader.ReadToEnd();
            }
            catch (IOException e)
            {
                response.ResponseCode = PostResponseCode.POST_IO_ERROR;
                return response;
            }
            reader.Close();
            reader.Dispose();

            Listing l = null;
            Address a = null;
            Person p = null;
            Utility u = null;

            try
            {
                l = (Listing)JsonConvert.DeserializeObject(res, typeof(Listing));
                a = l.Address;
                p = l.Pers;
                u = l.Utility;
            }
            catch (JsonSerializationException e)
            {
                response.ResponseCode = PostResponseCode.POST_DESERIALIZATION_ERROR;
                return response;
            }
            catch (JsonReaderException e)
            {
                response.ResponseCode = PostResponseCode.POST_JSON_READER_ERROR;
                return response;
            }

            try
            {
                using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
                {
                    sqlServerConnection.Open();
                    SqlCommand sqlServerCommand;

                    using (sqlServerCommand = new SqlCommand("INSERT INTO Address (Address_Type_id, street_address_1, street_address_2, city, state, zip_code) VALUES ("
                        + a.Address_Type.Address_Type_id + ",'" + a.street_address_1 + "','" + a.street_address_2 + "','" + a.city + "','" + a.state + "','" + a.zip_code + "');", sqlServerConnection))
                    {
                        sqlServerCommand.ExecuteNonQuery();
                    }

                    using (sqlServerCommand = new SqlCommand("SELECT Address_id FROM Address WHERE street_address_1 = '" + a.street_address_1 + "' AND " +
                                                                                                   " city = '" + a.city + "' AND " +
                                                                                                   " state = '" + a.state + "' AND " + 
                                                                                                   " zip_code = '" + a.zip_code + "';", sqlServerConnection))
                    {
                        using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                        {
                            int i = 0;
                            while (sqlReader.Read())
                            {
                                a.Address_id = Convert.ToInt32(sqlReader["Address_id"]);
                            }
                        }
                    }                

                    using (sqlServerCommand = new SqlCommand("INSERT INTO Utilities (water, power, cable, internet, other) VALUES ('"
                        + u.water + "','" + u.power + "','" + u.cable + "','" + u.internet + "','" + u.other + "');", sqlServerConnection))
                    {
                        sqlServerCommand.ExecuteNonQuery();
                    }

                    using (sqlServerCommand = new SqlCommand("SELECT Utility_id FROM Utilities WHERE water = '" + u.water + "' AND " +
                                                                                                    " power = '" + u.power + "' AND " +
                                                                                                    " cable = '" + u.cable + "' AND " +
                                                                                                    " internet = '" + u.internet + "' AND " + 
                                                                                                    " other = '" + u.other + "';", sqlServerConnection))
                    {
                        using (SqlDataReader sqlReader = sqlServerCommand.ExecuteReader())
                        {
                            while (sqlReader.Read())
                            {
                                u.Utility_id = Convert.ToInt32(sqlReader["Utility_id"]);
                            }
                        }
                    }
                    

                    using (sqlServerCommand = new SqlCommand("INSERT INTO Listing (Listing_Type_id, Pers_id, Address_id, Utility_id, listing_title, listing_desc, listing_rate, roommates, smoking, gender, furnished, square_ft, is_active) VALUES ("
                        + l.Listing_Type.Listing_Type_id + "," + l.Pers.Pers_id + "," + l.Address.Address_id + "," + l.Utility.Utility_id + ",'" + l.listing_title + "','" + l.listing_desc + "'," + l.listing_rate + "," + l.roommates + "," + l.smoking + ",'" + l.gender + "'," + l.furnished + "," + l.square_ft + ",1);", sqlServerConnection))
                    {
                        sqlServerCommand.ExecuteNonQuery();
                    }

                }

            }
            catch (SqlException e)
            {
                response.ResponseCode = PostResponseCode.POST_SQL_ERROR;
                return response;
            }
            catch (NullReferenceException e)
            {
                response.ResponseCode = PostResponseCode.POST_NULL_MEMBER_ERROR;
                return response;
            }

            return response;
        }
        #endregion New Listing
        //Updated: 7/23/2012
        #region Update Listing
        [WebInvoke(Method = "POST", UriTemplate = "listing/update", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        PostResponse UpdateListing(Stream streamdata)
        {
            setFormatJson();
            PostResponse response = new PostResponse();
            response.ResponseCode = PostResponseCode.POST_OK;

            StreamReader reader = new StreamReader(streamdata);
            string res = String.Empty;
            try
            {
                res = reader.ReadToEnd();
            }
            catch (IOException e)
            {
                response.ResponseCode = PostResponseCode.POST_IO_ERROR;
                return response;
            }
            reader.Close();
            reader.Dispose();

            Listing l = null;
            Address a = null;
            Person p = null;
            Utility u = null;

            try
            {
                l = (Listing)JsonConvert.DeserializeObject(res, typeof(Listing));
                a = l.Address;
                p = l.Pers;
                u = l.Utility;
            }
            catch (JsonSerializationException e)
            {
                response.ResponseCode = PostResponseCode.POST_DESERIALIZATION_ERROR;
                return response;
            }
            catch (JsonReaderException e)
            {
                response.ResponseCode = PostResponseCode.POST_JSON_READER_ERROR;
                return response;
            }

            try
            {
                using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
                {
                    sqlServerConnection.Open();
                    SqlCommand sqlServerCommand;

                    using (sqlServerCommand = new SqlCommand("UPDATE Listing SET Listing_Type_id = " + l.Listing_Type.Listing_Type_id +
                                                                               ",Pers_id = " + p.Pers_id +
                                                                               ",Address_id = " + a.Address_id +
                                                                               ",Utility_id = " + u.Utility_id +
                                                                               ",listing_title = " + l.listing_title +
                                                                               ",listing_desc = " + l.listing_desc +
                                                                               ",listing_rate = " + l.listing_rate +
                                                                               ",roommates = " + l.roommates +
                                                                               ",smoking = " + l.smoking +
                                                                               ",gender = " + l.gender +
                                                                               ",furnished = " + l.furnished +
                                                                               ",square_ft = " + l.square_ft +
                                                                               ",is_active = " + l.is_active + " WHERE Listing_id = " + l.Listing_id + ";", sqlServerConnection))
                    {
                        sqlServerCommand.ExecuteNonQuery();
                    }
                }

                using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
                {
                    sqlServerConnection.Open();
                    SqlCommand sqlServerCommand;

                    using (sqlServerCommand = new SqlCommand("UPDATE Address SET Address_Type_id = " + a.Address_Type.Address_Type_id +
                                                                               ",street_address_1 = " + a.street_address_1 +
                                                                               ",street_address_2 = " + a.street_address_2 +
                                                                               ",city = " + a.city +
                                                                               ",state = " + a.state +
                                                                               ",zip_code = " + a.zip_code +
                                                                               " WHERE Address_id = " + a.Address_id + ";", sqlServerConnection))
                    {
                        sqlServerCommand.ExecuteNonQuery();
                    }
                }

                using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
                {
                    sqlServerConnection.Open();
                    SqlCommand sqlServerCommand;

                    using (sqlServerCommand = new SqlCommand("UPDATE Pers SET Person_Type_id = " + p.Pers_Type.Pers_Type_id +
                                                                               ",first_name = " + p.first_name +
                                                                               ",last_name = " + p.last_name +
                                                                               ",password = " + p.password +
                                                                               ",username = " + p.username +
                                                                               ",phone = " + p.phone +
                                                                               ",email = " + p.email +
                                                                               ",email_confirm = " + p.email_confirm +
                                                                               ",is_active = " + p.is_active + " WHERE Pers_id = " + p.Pers_id + ";", sqlServerConnection))
                    {
                        sqlServerCommand.ExecuteNonQuery();
                    }
                }

                using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
                {
                    sqlServerConnection.Open();
                    SqlCommand sqlServerCommand;

                    using (sqlServerCommand = new SqlCommand("UPDATE Utility SET water = " + u.water +
                                                                               ",power = " + u.power +
                                                                               ",cable = " + u.cable +
                                                                               ",internet = " + u.internet +
                                                                               ",other = " + u.other +
                                                                               " WHERE Utility_id = " + u.Utility_id + ";", sqlServerConnection))
                    {
                        sqlServerCommand.ExecuteNonQuery();
                    }
                }

            }
            catch (SqlException e)
            {
                response.ResponseCode = PostResponseCode.POST_SQL_ERROR;
                return response;
            }
            catch (NullReferenceException e)
            {
                response.ResponseCode = PostResponseCode.POST_NULL_MEMBER_ERROR;
                return response;
            }

            return response;
        }
        #endregion Update Listing
        //Updated: 7/19/2012
        #region Delete Listing
        [WebInvoke(Method = "POST", UriTemplate = "listing/delete", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        PostResponse DeleteListing(Stream streamdata)
        {
            setFormatJson();
            PostResponse response = new PostResponse();
            response.ResponseCode = PostResponseCode.POST_OK;

            StreamReader reader = new StreamReader(streamdata);
            string res = String.Empty;
            try
            {
                res = reader.ReadToEnd();
            }
            catch (IOException e)
            {
                response.ResponseCode = PostResponseCode.POST_IO_ERROR;
                return response;
            }
            reader.Close();
            reader.Dispose();

            Listing l = null;

            try
            {
                l = (Listing)JsonConvert.DeserializeObject(res, typeof(Listing));
            }
            catch (JsonSerializationException e)
            {
                response.ResponseCode = PostResponseCode.POST_DESERIALIZATION_ERROR;
                return response;
            }
            catch (JsonReaderException e)
            {
                response.ResponseCode = PostResponseCode.POST_JSON_READER_ERROR;
                return response;
            }

            try
            {
                using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
                {
                    sqlServerConnection.Open();
                    SqlCommand sqlServerCommand;

                    using (sqlServerCommand = new SqlCommand("UPDATE Listing SET is_active = 0 WHERE Listing_id = " + l.Listing_id, sqlServerConnection))
                    {
                        sqlServerCommand.ExecuteNonQuery();
                    }
                }
            }
            catch (SqlException e)
            {
                response.ResponseCode = PostResponseCode.POST_SQL_ERROR;
                return response;
            }
            catch (NullReferenceException e)
            {
                response.ResponseCode = PostResponseCode.POST_NULL_MEMBER_ERROR;
                return response;
            }

            return response;
        }
        #endregion Delete Listing
        //Updated: 7/19/2012
        #region New Utility
        [WebInvoke(Method = "POST", UriTemplate = "utility/new", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        PostResponse NewUtility(Stream streamdata)
        {
            setFormatJson();
            PostResponse response = new PostResponse();
            response.ResponseCode = PostResponseCode.POST_OK;

            StreamReader reader = new StreamReader(streamdata);
            string res = String.Empty;
            try
            {
                res = reader.ReadToEnd();
            }
            catch (IOException e)
            {
                response.ResponseCode = PostResponseCode.POST_IO_ERROR;
                return response;
            }
            reader.Close();
            reader.Dispose();

            Utility u = null;
            try
            {
                u = (Utility)JsonConvert.DeserializeObject(res, typeof(Utility));
            }
            catch (JsonSerializationException e)
            {
                response.ResponseCode = PostResponseCode.POST_DESERIALIZATION_ERROR;
                return response;
            }
            catch (JsonReaderException e)
            {
                response.ResponseCode = PostResponseCode.POST_JSON_READER_ERROR;
                return response;
            }

            try
            {
                using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
                {
                    sqlServerConnection.Open();
                    SqlCommand sqlServerCommand;

                    using (sqlServerCommand = new SqlCommand("INSERT INTO Utility (water, power, cable, internet, other) VALUES ('"
                        + u.water + "','" + u.power + "','" + u.cable + "','" + u.internet + "','" + u.other + "');", sqlServerConnection))
                    {
                        sqlServerCommand.ExecuteNonQuery();
                    }
                }
            }
            catch (SqlException e)
            {
                response.ResponseCode = PostResponseCode.POST_SQL_ERROR;
                return response;
            }
            catch (NullReferenceException e)
            {
                response.ResponseCode = PostResponseCode.POST_NULL_MEMBER_ERROR;
                return response;
            }

            return response;
        }
        #endregion New Utility
        //Updated: 7/19/2012
        #region Update Utility
        [WebInvoke(Method = "POST", UriTemplate = "utility/update", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        PostResponse UpdateUtility(Stream streamdata)
        {
            setFormatJson();
            PostResponse response = new PostResponse();
            response.ResponseCode = PostResponseCode.POST_OK;

            StreamReader reader = new StreamReader(streamdata);
            string res = String.Empty;
            try
            {
                res = reader.ReadToEnd();
            }
            catch (IOException e)
            {
                response.ResponseCode = PostResponseCode.POST_IO_ERROR;
                return response;
            }
            reader.Close();
            reader.Dispose();

            Utility u = null;
            try
            {
                u = (Utility)JsonConvert.DeserializeObject(res, typeof(Utility));
            }
            catch (JsonSerializationException e)
            {
                response.ResponseCode = PostResponseCode.POST_DESERIALIZATION_ERROR;
                return response;
            }
            catch (JsonReaderException e)
            {
                response.ResponseCode = PostResponseCode.POST_JSON_READER_ERROR;
                return response;
            }

            try
            {
                using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
                {
                    sqlServerConnection.Open();
                    SqlCommand sqlServerCommand;

                    using (sqlServerCommand = new SqlCommand("UPDATE Utility SET water = " + u.water +
                                                                               ",power = " + u.power +
                                                                               ",cable = " + u.cable +
                                                                               ",internet = " + u.internet +
                                                                               ",other = " + u.other +
                                                                               " WHERE Utility_id = " + u.Utility_id + ";", sqlServerConnection))
                    {
                        sqlServerCommand.ExecuteNonQuery();
                    }
                }
            }
            catch (SqlException e)
            {
                response.ResponseCode = PostResponseCode.POST_SQL_ERROR;
                return response;
            }
            catch (NullReferenceException e)
            {
                response.ResponseCode = PostResponseCode.POST_NULL_MEMBER_ERROR;
                return response;
            }

            return response;
        }
        #endregion Update Utility
        //Updated: 7/19/2012
        #region Delete Utility
        [WebInvoke(Method = "POST", UriTemplate = "utility/delete", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        PostResponse DeleteUtility(Stream streamdata)
        {
            setFormatJson();
            PostResponse response = new PostResponse();
            response.ResponseCode = PostResponseCode.POST_OK;

            StreamReader reader = new StreamReader(streamdata);
            string res = String.Empty;
            try
            {
                res = reader.ReadToEnd();
            }
            catch (IOException e)
            {
                response.ResponseCode = PostResponseCode.POST_IO_ERROR;
                return response;
            }
            reader.Close();
            reader.Dispose();

            Utility u = null;

            try
            {
                u = (Utility)JsonConvert.DeserializeObject(res, typeof(Utility));
            }
            catch (JsonSerializationException e)
            {
                response.ResponseCode = PostResponseCode.POST_DESERIALIZATION_ERROR;
                return response;
            }
            catch (JsonReaderException e)
            {
                response.ResponseCode = PostResponseCode.POST_JSON_READER_ERROR;
                return response;
            }

            try
            {
                using (SqlConnection sqlServerConnection = new SqlConnection(sqlconnstring))
                {
                    sqlServerConnection.Open();
                    SqlCommand sqlServerCommand;

                    using (sqlServerCommand = new SqlCommand("UPDATE Utility SET is_active = 0 WHERE Utility_id = " + u.Utility_id, sqlServerConnection))
                    {
                        sqlServerCommand.ExecuteNonQuery();
                    }
                }
            }
            catch (SqlException e)
            {
                response.ResponseCode = PostResponseCode.POST_SQL_ERROR;
                return response;
            }
            catch (NullReferenceException e)
            {
                response.ResponseCode = PostResponseCode.POST_NULL_MEMBER_ERROR;
                return response;
            }

            return response;
        }
        #endregion Delete Utility

        #endregion

    }
}
